#include "usart_stub.h"
#include "hilog/log_cpp.h"
namespace OHOS {
const HiviewDFX::HiLogLabel usart_log{LOG_APP,0xD001800,""};

namespace Usart_Standard{


//这个stub的名字是哪里来的，尚且未知
int32_t UsartAbilityStub::OnRemoteRequest(uint32_t code,
    MessageParcel& data, MessageParcel &reply, MessageOption &option){
    using namespace HiviewDFX;
    using std::string;
    switch ( code ) {
        case OP::OPEN:{//virtual int open(std::string name);
            string name=data.ReadString();
            int res=open(name);
            if(res!=0){
                HiLog::Error(usart_log,"[USART ERROR] open serial \"%s\" failed with %d\n",name.c_str(),res);
            }
            break;
        }
        case OP::CLOSE:{
            string name=data.ReadString();
            close(name);
            break;
        }
        case OP::IS_OPEN:{
            string name=data.ReadString();
            bool is_open_res=is_open(name);
            reply.WriteBool(is_open_res);
            break;
        }
        case OP::WRITE:{
            string name=data.ReadString();
            string message=data.ReadString();
            write(name,message);
            break;
        }
        case OP::READ_NUM:{
            string name=data.ReadString();
            int num=data.ReadInt64();
            string readbuf=read(name,num);
            reply.WriteString(readbuf);
            break;
        }
        case OP::READLINE:{
            string name=data.ReadString();
            string readbuf=readline(name);
            reply.WriteString(readbuf);
            break;
        }
        case OP::LOOP_BEGIN:{
            string name=data.ReadString();
            begin_read_loop(name);
            break;
        }
        case OP::LOOP_END:{
            string name=data.ReadString();
            end_read_loop(name);
            break;
        }
        case OP::LOOP_READ:{
            string name=data.ReadString();
            string readbuf=read_from_looper(name);
            reply.WriteString(readbuf);
            break;
        }
        default:break;
    }
    return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}//namespace Usart_Standard
}//namespace OHOS